﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace GameStateManagement.Mine
{
    public class MyMenuEntry : CommandEntry
    {

        public MyMenuEntry(string strTexture)
            : base(strTexture)
        {
            SelectedColor = Color.Yellow;
            Color = Color.White;
        }

        public Color SelectedColor { get; set; }
        public Color Color { get; set; }

        //float selectionFade;

        public override void Draw(GameScreen screen, bool isSelected, GameTime gameTime)
        {
            
            // Draw the selected entry in yellow, otherwise white.
            Color color = isSelected ? SelectedColor : Color;

            // Pulsate the size of the selected menu entry.
            double time = gameTime.TotalGameTime.TotalSeconds;

            float pulsate = (float)Math.Sin(time * 6) + 1;

            float scale = 1 + pulsate * 0.05f * selectionFade;

            // Modify the alpha to fade text out during transitions.
            color *= screen.TransitionAlpha;

            // Draw text, centered on the middle of each line.
            ScreenManager screenManager = screen.ScreenManager;
            SpriteBatch spriteBatch = screenManager.SpriteBatch;
            SpriteFont font = screenManager.Font;

            Vector2 origin = new Vector2(0, font.LineSpacing / 2);

            spriteBatch.DrawString(font, text, position, color, 0,
                                   origin, scale, SpriteEffects.None, 0);

        }


        public override int GetHeight(GameScreen screen)
        {
            return screen.ScreenManager.Font.LineSpacing;
        }

        public override int GetWidth(GameScreen screen)
        {
            return (int)screen.ScreenManager.Font.MeasureString(Text).X;
        }

        public override void Update(GameScreen screen, bool isSelected, GameTime gameTime)
        {

            float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;

            if (isSelected)
                selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
            else
                selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
        }

    }
}
